import { findByAgentBySelectList } from '@/services/agent';
import { agentEdit } from '@/services/users';
import {
  ModalForm,
  ProFormSelect,
  ProFormText,
} from '@ant-design/pro-components';
import { Form, message } from 'antd';
import React from 'react';

const AgentSetting: React.FC<any> = (props) => {
  const { user } = props;

  const [form] = Form.useForm<{
    userId: number;
    agentId: number;
  }>();
  return (
    <ModalForm<{
      userId: number;
      agentId: number;
    }>
      title="代理等级"
      width={400}
      trigger={<a key="link">修改代理等级</a>}
      initialValues={{
        userId: props.id,
        agentId: user.agentId,
      }}
      layout="vertical"
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => console.log('run'),
      }}
      submitTimeout={2000}
      onFinish={(values) => {
        console.log(values);
        message.success('提交成功');
        return new Promise<boolean>((resolve, reject) => {
          agentEdit(values)
            .then((res) => {
              resolve(true);
              message.success('提交成功');
            })
            .catch((err) => {
              reject(false);
              message.error('提交失败');
            });
        });
      }}
    >
      <ProFormText
        name="userId"
        hidden={true}
        initialValue={user.id}
      ></ProFormText>
      <ProFormText
        name="agentName"
        label="当前代理等级"
        disabled={true}
        initialValue={user.agentName}
      ></ProFormText>
      <ProFormSelect
        name={'agentId'}
        label={'选择新等级'}
        debounceTime={300}
        request={findByAgentBySelectList}
      />
    </ModalForm>
  );
};

export default AgentSetting;
//96, 100, 104, 105, 107.239, 230, 361, 1161, 1162, 1148, 238
